Using npm Libraries in Code Blocks
DevAssure now offers a powerful new feature: Library Preferences, allowing you to seamlessly integrate external npm packages directly into your code blocks. This enhancement significantly expands the capabilities of your DevAssure projects by enabling you to leverage the vast ecosystem of npm libraries.
How to Use Library Preferences
The Library Preferences section, accessible within your Project Preferences, provides a centralized location to manage the npm packages required for your DevAssure project.
1. Accessing Library Preferences:
- Navigate to Project Preferences.
- Select the Libraries tab.
2. Adding npm Packages:
In the "Add npm packages" section, you will find a table to list your desired npm packages.
-
npm package name: Enter the exact name of the npm package you wish to include (e.g.,
jsonwebtoken
,@faker-js/faker
). -
version: Specify the version of the package you want to use. You can use standard npm versioning syntax (e.g.,
^9.0.2
,^9.8.0
,1.0.0
,latest
).- Example:
jsonwebtoken
with version^9.0.2
@faker-js/faker
with version^9.8.0
- Example:
-
Click "Add npm package" to add more rows if needed.

3. Utilizing npm Packages in Code Blocks:
Once an npm package is listed in your Library Preferences, it becomes available for use within your code blocks. You can require
these packages just like you would in a standard Node.js environment.
Example:
To use the @faker-js/faker
library to generate a random number:
const { fakerDE: faker } = require('@faker-js/faker'); // 'fakerDE' is an example of a specific locale, 'faker' is the main export
faker.seed(567); // Optional: Seed the faker generator for reproducible results
const firstRandom = faker.number.int();
// You can then use the generated value, for example, in a print log:
Print log ${firstRandom}
